package com.example.babyapp;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.util.SparseBooleanArray;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends Activity {
	
	Button btn;
	String strUsername, strPassword ;
	EditText username, password;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        setOrientation();
        
        btn = (Button) findViewById(R.id.loginBtn);
        btn.setOnClickListener(new OnClickListener() {
			
			public void onClick(View v) {
				
		        username = (EditText) findViewById(R.id.usernameField);
		        password = (EditText) findViewById(R.id.passwordField);
		        
		        strUsername = username.getText().toString();
		        strPassword = password.getText().toString();
		        
		        if (strUsername.equals("NIH") && strPassword.equalsIgnoreCase("12345")) {
		        	gotoHomeActivity(v);
		        } else {
		        	Toast.makeText(getApplicationContext(), "Please Re-check Data", Toast.LENGTH_SHORT).show();
		          }	
		        }
		});
        
    }
    
    
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }
    
    
    public void gotoHomeActivity(View v){
    	Intent intent = new Intent(this, HomeActivity.class);
    	startActivity(intent);
    }
    
	protected void setOrientation() {
    	int current = getRequestedOrientation();
    	if(current != ActivityInfo.SCREEN_ORIENTATION_PORTRAIT){
    		setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    	}
    }
	
}
